package br.com.atibrasil.fx.aplication;

import java.awt.Color;
import java.awt.Point;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;

public class Inicial extends JWindow {
	private static final long serialVersionUID = 1L;
	private static Properties p = new Properties();  	
	private static String URL_LOGO_INIT = "URL_LOGO_INIT";
	private static String URL_LOGO_RELATORIO= "URL_LOGO_RELATORIO";	
	private static String APP_NOME= "APP_NOME";	
	public static ImageIcon LOGO_INIT;
	public static ImageIcon LOGO_RELATORIO;	
	public static InputStream LOGO_RELATORIO_STREAM;
	public static String NOME_SISTEMA;	
	
	private JProgressBar barraProgresso;
	public Inicial() throws InterruptedException, IOException{	
		p.load(Inicial.class.getResourceAsStream("/config.properties"));
		LOGO_INIT = new ImageIcon(getClass().getResource(p.getProperty(URL_LOGO_INIT))); 		
		LOGO_RELATORIO = new ImageIcon(getClass().getResource(p.getProperty(URL_LOGO_RELATORIO)));	
		LOGO_RELATORIO_STREAM = Inicial.class.getClass().getResourceAsStream(p.getProperty(URL_LOGO_RELATORIO));
		NOME_SISTEMA = p.getProperty(APP_NOME);			
		@SuppressWarnings("static-access")
		int w = getToolkit().getDefaultToolkit().getScreenSize().width;
		@SuppressWarnings("static-access")		
		int h = getToolkit().getDefaultToolkit().getScreenSize().height;
		int z = 2;
		int x = (w - 521) / z;
		int y = (h - 335) / z;
		
		JLabel img = new JLabel(LOGO_INIT);
		img.setLocation(new Point(0,0));
		img.setSize(521, 335);
		
		this.setLayout(null);
		this.add(img);
		this.setLocation(new Point(x,y));
		this.setSize(521, 335);
		this.setVisible(true);
		
		barraProgresso = new JProgressBar();
		barraProgresso.setBackground(new Color(0,102,52));
		barraProgresso.setBounds(0, 315, 521, 20);
		barraProgresso.setStringPainted(true);
		this.add(barraProgresso);
		
		new Thread(){
			public void run(){
				for (int progress = 0; progress < 101; progress++) {
					try {
						barraProgresso.setValue(progress);
						sleep(10);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}.start();
		Thread.sleep(3000);
		GUILogin login = new GUILogin();
//		login.setVisible(true);
		this.setVisible(false);
		
	}
	
	public static InputStream getLogoStream(){
		LOGO_RELATORIO_STREAM = Inicial.class.getClass().getResourceAsStream(p.getProperty(URL_LOGO_RELATORIO)); 
		return LOGO_RELATORIO_STREAM;
	}
	
	public static void main (String args[]) throws InterruptedException, IOException {
		new Inicial();
	}


}
